package com.technology.education.ui.common.setting

import android.view.ViewGroup
import android.widget.LinearLayout
import com.angcyo.dsladapter.dpi
import com.angcyo.dsladapter.dslItem
import com.technology.education.R
import com.technology.education.base.BaseRecyclerTopBarFragment
import com.technology.education.data.AppData
import com.technology.education.dslitem.ItemColumnTitleText
import com.technology.education.dslitem.style.DrawableStyle
import com.technology.education.ext.*
import com.technology.education.widget.CommonButton
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

class SettingFragment : BaseRecyclerTopBarFragment<BaseViewModel>() {
    override fun initViews() {
        setTitle("设置")
    }

    override fun lazyLoadData() {
        renderAdapter {
            dslItem(
                ItemColumnTitleText(
                    "平台注册协议",
                    titleDrawable = DrawableStyle(leftDrawable = R.mipmap.icon_protocal)
                )
            ) {
                itemClick = {
                    toWebActivity("平台注册协议", AppData.REGISTER_PROTOCOL)
                }
            }
            dslItem(
                ItemColumnTitleText(
                    "清除缓存",
                    titleDrawable = DrawableStyle(leftDrawable = R.mipmap.icon_delete)
                )
            ) {
                itemClick = {
                    toast("缓存清除成功")
                }
            }
            dslItem(
                ItemColumnTitleText(
                    "关于我们",
                    titleDrawable = DrawableStyle(leftDrawable = R.mipmap.icon_about_us)
                )
            ) {
                itemClick = {
                    toWebActivity("关于我们", AppData.ABOUT_US)
                }
            }
        }

        view?.findViewById<LinearLayout>(R.id.ll_content)?.apply {
            removeAllViews()
            addView(CommonButton(requireContext()).apply {
                text = "退出登录"
                setTextColor(getColor(R.color.white))
                textSize = 18f
                setBackgroundColor(getColor(R.color.red))
                setOnClickListener {
                    getAppViewModel().logout()
                    logout()
                }
            }, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 44 * dpi))
        }
    }

    override fun createObserver() {

    }
}